package util;

import java.util.HashMap;
import java.util.Map;

import main.Generator;

public class GenContext {

    private Map<String, Generator> generators;
    private Map<Integer, String> captures;

    public GenContext() {
        this.captures = new HashMap<Integer, String>();
        this.generators = new HashMap<String, Generator>();
    }

    public void clear() {
        captures.clear();
        generators.clear();
    }

    public String getCapture(int idx) {
        if (captures.containsKey(idx)) {
            return captures.get(idx);
        }
        throw new RuntimeException("Invalid capture index: " + idx);
    }

    public void setCapture(int idx, String content) {
        captures.put(idx, content);
    }

    public Generator getGenerator(String name) {
        if (generators.containsKey(name)) {
            return generators.get(name);
        }
        throw new RuntimeException("Invalid generator name: " + name);
    }

    public void setGenerator(String name, Generator cb) {
        generators.put(name, cb);
    }
}
